package com.xinda.admin.shiro;

import javax.annotation.Resource;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xinda.admin.pojo.Admin;
import com.xinda.admin.service.AdminService;



/**
* @author 作者 E-mail:
* @version 创建时间：2017年9月6日 上午11:46:53
* 类说明
*/

public class MyRealm extends AuthorizingRealm{
	
	
	@Resource
	private AdminService adminService;
	
	
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
			throws AuthenticationException{
		 //获取用户账号
        String adminName = token.getPrincipal().toString();
        Admin admin = adminService.findAdminByAdminName(adminName);
        if (admin != null){
            AuthenticationInfo authenticationInfo = 
            		new SimpleAuthenticationInfo(admin.getAdminName(),admin.getPassword(),"a") ;
            return authenticationInfo ;
        }else{
            return  null ;
        }
	}

	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) {
		// TODO Auto-generated method stub
		return null;
	}
}
